package com.tronsis.distribution.biz.impl;

import android.app.Activity;

import com.google.gson.reflect.TypeToken;
import com.tronsis.distribution.bean.AgentExitBean;
import com.tronsis.distribution.bean.ApplyDepositBean;
import com.tronsis.distribution.bean.AskPayBean;
import com.tronsis.distribution.bean.AskQuitBean;
import com.tronsis.distribution.bean.ProductDetailBean;
import com.tronsis.distribution.bean.QuitDepositBean;
import com.tronsis.distribution.bean.ReturnDetailBean;
import com.tronsis.distribution.bean.UpgradeBean;
import com.tronsis.distribution.bean.UpgradeDetailBean;
import com.tronsis.distribution.biz.UpgradeBiz;
import com.tronsis.distribution.http.Url;
import com.tronsis.library.http.HttpCallBack;
import com.tronsis.library.http.ListBean;
import com.tronsis.library.http.RequestClient;
import com.tronsis.library.http.RequestMethod;
import com.tronsis.library.http.UICallBack;

import java.util.List;

public class UpgradeBizImpl implements UpgradeBiz {
    @Override
    public void getUpgrades(Activity activity, int page, int size, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<UpgradeBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("page", String.valueOf(page), "size", String.valueOf(size)).excute(RequestMethod.GET, Url.UPGRADE);
    }

    @Override
    public void submitUpgradeApply(Activity activity, String level, String region, String type, final UICallBack callBack) throws Exception {

        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("level", level, "region", region, "type", type).excute(RequestMethod.POST, Url.UPGRADE);

    }

    @Override
    public void getUpgradeDetail(Activity activity, String upgradeId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, UpgradeDetailBean.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.UPGRADE + "/" + upgradeId);
    }

    @Override
    public void deleteUpgrade(Activity activity, String upgradeId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.DELETE, Url.UPGRADE + "/" + upgradeId);
    }

    @Override
    public void upgradePay(Activity activity, String payeeId, String paymentFid, String points, String upgradeId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("payeeId", payeeId, "paymentFid", paymentFid, "points", points).excute(RequestMethod.GET, Url.UPGRADE + "/" + upgradeId + "/pay");
    }

    @Override
    public void askPayDetail(Activity activity, String askPayId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, AskPayBean.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.UPGRADE_ASK_PAY + "/" + askPayId);
    }

    @Override
    public void submitAskPay(Activity activity, String askPayId, String paymentFid, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("paymentFid", paymentFid).excute(RequestMethod.POST, Url.UPGRADE_ASK_PAY + "/" + askPayId + "/submit");
    }

    @Override
    public void askQuits(Activity activity, int page, int size, String state, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<AskQuitBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("page", String.valueOf(page), "size", String.valueOf(size), "state", state).excute(RequestMethod.GET, Url.UPGRADE_ASK_QUIT);
    }

    @Override
    public void askQuitPay(Activity activity, String askQuitId, String stockFid, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("stockFid", stockFid).excute(RequestMethod.POST, Url.UPGRADE_ASK_QUIT + "/" + askQuitId);
    }

    @Override
    public void askQuitPass(Activity activity, String askQuitId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("askQuitId", askQuitId).excute(RequestMethod.PATCH, Url.UPGRADE_ASK_QUIT + "/" + askQuitId + "/pass");
    }

    @Override
    public void askQuitReject(Activity activity, String askQuitId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("askQuitId", askQuitId).excute(RequestMethod.PATCH, Url.UPGRADE_ASK_QUIT + "/" + askQuitId + "/reject");
    }

    @Override
    public void confirmFid(Activity activity, String agentId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("id", agentId).excute(RequestMethod.GET, Url.UPGRADE + "/confirmFid");
    }

    @Override
    public void confirmFail(Activity activity, String agentId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("id", agentId).excute(RequestMethod.GET, Url.UPGRADE + "/confirmFail");
    }

    @Override
    public void quitDetail(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, AgentExitBean.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.UPGRADE_QUIT);

    }

    @Override
//    public void quitApply(Activity activity, String addrId, String clear, Double profitMoney, String type, final UICallBack callBack) throws Exception {
    public void quitApply(Activity activity, String addrId, String clear,  String type, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("addrId", addrId, "clear", clear, "type", type).excute(RequestMethod.POST, Url.UPGRADE_QUIT);
//        }).addParameter("addrId", addrId, "clear", clear, "money", String.valueOf(profitMoney), "type", type).excute(RequestMethod.POST, Url.UPGRADE_QUIT);
    }

    @Override
    public void quitProductInfo(Activity activity, String quitId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<List<ProductDetailBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.UPGRADE_QUIT + "/" + quitId + "/products");
    }

    @Override
    public void quitConfirm(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter().excute(RequestMethod.POST, Url.UPGRADE_QUIT + "/confirm");
    }


    @Override
    public void getQuitDeposit(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<List<QuitDepositBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.QUIT_DEPOSIT);
    }

    @Override
    public void getApplyDeposit(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ApplyDepositBean>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.APPLY_DEPOSIT);
    }

    @Override
    public void submitDeposit(Activity activity, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.SUBMIT_DEPOSIT);
    }

    @Override
    public void getReturnDetail(Activity activity, String id, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ReturnDetailBean>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("id", id).excute(RequestMethod.GET, Url.DEPOSIT_DETAIL);
    }

    @Override
    public void getAskcontr(Activity activity, String mUserLevel, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, Double[].class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("level", mUserLevel).excute(RequestMethod.GET, Url.UPGRADE_ASKCONTR);
    }
}
